//
//  BaseViewController.m
//  TodatPlay
//
//  Created by dllo on 16/8/27.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "BaseViewController.h"
#import "FeaturedViewController.h"
#import "FoundViewController.h"
#import "SceneViewController.h"
#import "MineViewController.h"
#import "LoginSuccessViewController.h"
#import "LoginDataData.h"
#import "LoginData.h"
#import "LoginRootClass.h"
#import "LoginDataRootClass.h"
#import "AppDelegate.h"
@interface BaseViewController ()
@property (nonatomic, strong) LoginDataRootClass *DataModel;

@end

@implementation BaseViewController {
    BOOL isLogin;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // 判断是否自动登录
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSDictionary *dic = [user objectForKey:@"LoginData"];
//    NSDictionary *exitDic = [user objectForKey:@"exitDic"];
//    AppDelegate *app = [[UIApplication sharedApplication] delegate];
    
    self.DataModel = [LoginDataRootClass modelWithDic:dic];
    if ( self.DataModel.errorCode == 0 && self.DataModel.data != nil) {
        isLogin = YES;
    } else {
        isLogin = NO;
    }

    // 创建四个ViewController
    
    FeaturedViewController *featuredViewController = [[FeaturedViewController alloc] init];
    FoundViewController *foundViewController = [[FoundViewController alloc] init];
    SceneViewController *sceneViewController = [[SceneViewController alloc] init];
    MineViewController *mineViewController = [[MineViewController alloc] init];
    LoginSuccessViewController *loginSuccessVC = [[LoginSuccessViewController alloc] init];
    // 创建四个Navigation
    UINavigationController *featureNavi = [[UINavigationController alloc] initWithRootViewController:featuredViewController];
    UINavigationController *foundNavi = [[UINavigationController alloc] initWithRootViewController:foundViewController];
    UINavigationController *sceneNavi = [[UINavigationController alloc] initWithRootViewController:sceneViewController];
    UINavigationController *mineNavi = [[UINavigationController alloc] initWithRootViewController:mineViewController];
    UINavigationController *loginNavi = [[UINavigationController alloc] initWithRootViewController:loginSuccessVC];
    // 创建title和image
    featureNavi.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"精选" image:[UIImage imageNamed:@"icon_tab1_normal"] selectedImage:[[UIImage imageNamed:@"icon_tab1_press"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    foundNavi.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"发现" image:[UIImage imageNamed:@"icon_tab2_normal"] selectedImage:[[UIImage imageNamed:@"icon_tab2_press"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    sceneNavi.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"现场" image:[UIImage imageNamed:@"icon_tab3_normal"] selectedImage:[[UIImage imageNamed:@"icon_tab3_press"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    mineNavi.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我" image:[UIImage imageNamed:@"icon_tab4_normal"] selectedImage:[[UIImage imageNamed:@"icon_tab4_press"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    loginNavi.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我" image:[UIImage imageNamed:@"icon_tab4_normal"] selectedImage:[[UIImage imageNamed:@"icon_tab4_press"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    // 使得选中的tabbar字体颜色为黑色
    [[UITabBar appearance] setTintColor:[UIColor blackColor]];
    // 将四个控制器加入到tabbar中
    if (dic != nil) {
        self.viewControllers = @[featureNavi, foundNavi, sceneNavi, loginNavi];
    } else {
        self.viewControllers = @[featureNavi, foundNavi, sceneNavi, mineNavi];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
